package com.training.java.core.collections.one;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;


public class TreeSetDemo {

	public static void main(String[] args) {
		Set<String> students = new TreeSet<String>();//If you want to maintain the natural order go for TreeSet. It is slow.
		//List list = new LinkedList(); 
		
		
		students.add("Sam");
		students.add("Henry");
		students.add("Almas");
		students.add("vinod");// linked list and array list also accepts duplicates
		students.add("vinod");
		students.add("almas");
		
		//Car focus = new Car("Ford", "Focus", 2014);
		//list.add(focus); // String and objects are not compatible types and therefore
		//will throw an error when system will try to print after Henry
		
		
		//Read from list
		Iterator<String> ite = students.iterator();
		
		while(ite.hasNext()) // read until hasNext value is true
		{
			String studentName = ite.next();
			System.out.println("Student name = " + studentName);
		}
		
		System.out.println("*********************");
		//Read the same list using for each loop
		for(String studentName : students)
		{
			System.out.println("Student name = " + studentName);
		}
	}
	}
